package com.cxs.controller;
import com.cxs.service.NewsDetailService;
import cxs.utils.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 * @Author:cxs
 * @Date:2021/10/9  16:41
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
@RestController
@RequestMapping("/news")
public class NewsDetailController {
    @Autowired
    private NewsDetailService newsDetailService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(@RequestParam(value = "title",required = false)String title,
                       @RequestParam(value = "pageNum",required = true,defaultValue = "1") Integer pageNum,
                       @RequestParam(value = "pageSize",required = true,defaultValue = "5") Integer pageSize){
        return Result.OK("ok",newsDetailService.list(pageNum, pageSize, title));
    }

    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public Result delete(@PathVariable("id") Long id){
        if(id == null) return Result.failare("id不能为空");
        return Result.OK("删除成功",newsDetailService.delete(id));
    }
}
